package com.bw.produce.controller;



import com.bw.common.core.web.controller.BaseController;
import com.bw.common.core.web.domain.AjaxResult;
import com.bw.common.core.web.page.TableDataInfo;
import com.bw.produce.domain.dto.PropertyDTO;

import com.bw.produce.domain.vo.PropertyVO;
import com.bw.produce.query.PropertyQueryObject;
import com.bw.produce.service.IPropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lemon
 * @date 2024/11/14 22:26
 **/
@RestController
@RequestMapping("/property")
public class PropertyController extends BaseController {

    @Autowired
    private IPropertyService propertyService;


    /**
     * 根据参数编号获取详细信息
     */
    @GetMapping("/{propertyId}")
    public AjaxResult getInfo(@PathVariable Long propertyId)
    {
        return success(propertyService.getInfo(propertyId));
    }

    /**
     * 获取品牌列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PropertyQueryObject queryParams){
        startPage();
        List<PropertyVO> list = propertyService.selectPropertyList(queryParams);
        return getDataTable(list);
    }


    /**
     * 新增品牌
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PropertyDTO propertyDTO) {
        propertyService.insertProperty(propertyDTO);
        return toAjax(true);
    }

    /**
     * 修改品牌
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PropertyDTO propertyDTO) {
        propertyService.updateProperty(propertyDTO);
        return toAjax(true);
    }

    /**
     * 删除品牌
     */
    @DeleteMapping("/{propertyId}")
    public AjaxResult remove(@PathVariable Long[] propertyId) {
        propertyService.deletePropertyById(propertyId);
        return toAjax(true);
    }
}
